﻿namespace CoverageRunner.Core;

public class RunnerConfig
{
    /// <summary>
    ///     可执行文件路径，要运行的程序名
    /// </summary>
    public string ExecutablePath { get; set; } = "";

    /// <summary>
    ///     覆盖率输出位置，文件夹
    /// </summary>
    public string ReportDirectory { get; set; } = "";

    /// <summary>
    ///     运行的参数，是可执行程序的运行参数
    /// </summary>
    public List<string> Arguments { get; set; } = new();

    /// <summary>
    ///     覆盖率包含的源代码路径
    /// </summary>
    public List<string> IncludeSourcePaths { get; set; } = new();

    /// <summary>
    ///     覆盖率忽略的源代码路径
    /// </summary>
    public List<string> ExcludeSourcePaths { get; set; } = new();

    /// <summary>
    ///     附加的环境变量，保证可执行程序运行正常
    /// </summary>
    public List<string> Environments { get; set; } = new();

    /// <summary>
    ///     覆盖率分析包含的模块名（dll/so文件名）
    /// </summary>
    public List<string> IncludeModuleFilters { get; set; } = new();

    /// <summary>
    ///     覆盖率分析排除的模块名（dll/so文件名）
    /// </summary>
    public List<string> ExcludeModuleFilters { get; set; } = new();

    /// <summary>
    /// 使用哪个Runner去执行
    /// </summary>
    public string RunnerId { get; set; } = "";

    private bool Equals(RunnerConfig other)
    {
        return ExecutablePath == other.ExecutablePath
               && ReportDirectory == other.ReportDirectory
               && Arguments.All(other.Arguments.Contains)
               && IncludeSourcePaths.All(other.IncludeSourcePaths.Contains)
               && ExcludeSourcePaths.All(other.ExcludeSourcePaths.Contains)
               && Environments.All(other.Environments.Contains)
               && IncludeModuleFilters.All(other.IncludeModuleFilters.Contains)
               && ExcludeModuleFilters.All(other.ExcludeModuleFilters.Contains)
               && RunnerId == other.RunnerId;
    }

    public override bool Equals(object? obj)
    {
        if (ReferenceEquals(null, obj)) return false;
        if (ReferenceEquals(this, obj)) return true;
        if (obj.GetType() != GetType()) return false;
        return Equals((RunnerConfig) obj);
    }

    public override int GetHashCode()
    {
        HashCode code = new();
        code.Add(ExecutablePath);
        code.Add(ReportDirectory);
        code.Add(Arguments);
        code.Add(IncludeSourcePaths);
        code.Add(ExcludeSourcePaths);
        code.Add(Environments);
        code.Add(IncludeModuleFilters);
        code.Add(ExcludeModuleFilters);
        code.Add(RunnerId);
        return code.ToHashCode();
    }
}